class Solution:
    def maxTurbulenceSize(self, A: list) -> int:
        if len(A) == 0:
            return 0
        GT = ">"
        LT = "<"
        EQ = "="
        res = 1
        cur = 1
        last_symbol = EQ
        for i in range(1, len(A)):
            if A[i] > A[i - 1]:
                symbol = GT
            elif A[i] < A[i - 1]:
                symbol = LT
            else:
                symbol = EQ
            if symbol == EQ:
                cur = 1
            elif symbol == last_symbol:
                cur = 2
            else:
                cur += 1
            res = max(res, cur)
            last_symbol = symbol
        return res
